var templageContnetJs = require('t_content/t_content.js');
var apiFun = require('../../utils/api.js');

var data ={
  "magicId": 4,
  "title": "好像听撩人的话",
  "createTime": "2018-07-05 17:05:17",
  "colorScheme": {
    "themeId": 2,
    "themeName": "黄色系",
    "isDelete": 1,
    "bgColor": "-webkit-linear-gradient(top, rgb(234,185,45) 0%,rgb(199,152,16) 100%)",
    "navBgColor": "#E5B900",
    "navFontColor": "#ffffff",
    "qBgColor": "#ffffff",
    "qAuthorColor": "#ffffff",
    "qContentFontColor": "black",
    "aBgColor": "#ffffff",
    "aAuthorColor": "#ffffff",
    "aContentFontColor": "black",
    "buttonFontColor": "black",
    "buttonBgColor": "rgba(255, 255, 255, 0.5)"
  }
};


Page({

  //init data
  data:{
    list: {},
    animationMagicTopic:{},
    animationIndex:0,
    isShowAnswerMagic:true,
    isLoading: false,
    footerConfig: {
      isFooterMagic: false,
      isFooterZb: true
    }
  },

  //onLoad
  onLoad:function(event){

  },

  //onShow
  onShow: function () {

    //animation 简介
    var animationMagicTopic = wx.createAnimation({
      transformOrigin: "50% 50%",
      duration: 1000,
      timingFunction: "ease",
      delay: 0
    })

    this.animationMagicTopic = animationMagicTopic 
    this.setData({
      animationMagicTopic: animationMagicTopic.export()
    })

    //animation MagicContent 内容
    var animationMagicContent = wx.createAnimation({
      transformOrigin: "50% 50%",
      duration: 1000,
      timingFunction: "ease",
      delay: 0
    })

    this.animationMagicContent = animationMagicContent
    this.setData({
      animationMagicContent: animationMagicContent.export(),
    })

  },

  //lock Magic
  lockMagic:function(event){

    var currentThemeId = '';
    var thisList = this.data.list;
    var that = this;

    if (thisList.colorScheme) {
      currentThemeId = thisList.colorScheme.themeId;
    }
  
    this.setData({ 
      isLoading:true
    })

    //api requeset divination
    apiFun.getDivinationList(
      {
        userId: 1,
        currentThemeId: currentThemeId,
        
        success: function (res) {

          //set view content 
          res.list.divinationShowContent = res.list.divinationContent;

          //set first tarbar bg color and font color
          if (res.list != false) {
            var firstBgColor = res.list['colorScheme']['navBgColor'];
            var firstFrontColor = res.list['colorScheme']['navFontColor'];
            console.log(firstFrontColor);
            wx.setNavigationBarColor({
              frontColor: firstFrontColor,
              backgroundColor: firstBgColor,
              animation: {
                duration: 400,
                timingFunc: 'easeIn'
              }
            })
          } 

          that.setData({
            list: res.list,
            loadingMagic: false,
            isLoading:false
          })

        },
        
        fail:function(res){
          return false;
        }
      }
    )


    //问题滑动
    var systemInfo = wx.getSystemInfoSync();
    this.animationMagicTopic.translateY(-780 / 750 * systemInfo.windowWidth).step();
    this.setData({
      animationMagicTopic: this.animationMagicTopic.export(),
    })
    
    //答案滑动
    this.animationMagicContent.translateY(- 700 / 750 * systemInfo.windowWidth).step();
    this.setData({
      animationMagicContent:this.animationMagicContent.export()
    })

    this.setData({
      isShowAnswerMagic: false
    })

  },

  //lock Magic
  closeAnswerMagic: function (event) {

    var systemInfo = wx.getSystemInfoSync();
    this.animationMagicTopic.translateY(10 / 750 * systemInfo.windowWidth).step();

    this.setData({
      animationMagicTopic: this.animationMagicTopic.export(),
    })

    //旧的上去
    this.animationMagicContent.translateY(670 / 750 * systemInfo.windowWidth).step();
    this.setData({
      animationMagicContent: this.animationMagicContent.export()
    })

    this.setData({
      isShowAnswerMagic: true
    })

  },
  
  jumpMagic: function (event) {
    wx.redirectTo({
      url: '/pages/mc_new_u/mc'
    })
  },
  JumpZb: function (event) {
    wx.redirectTo({
      url: '/pages/zb/zb'
    })
  }


})